package file

import (
	"context"
	"net/http"

	"github.com/zeromicro/go-zero/core/logx"

	"2106A-zg6/baidu/gateway/internal/svc"
	"2106A-zg6/baidu/gateway/internal/types"
	"2106A-zg6/baidu/srv/baiduclient"
)

type DeleteWpFileLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDeleteWpFileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteWpFileLogic {
	return &DeleteWpFileLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DeleteWpFileLogic) DeleteWpFile(req *types.DeleteFile) (resp *types.Response, err error) {

	//  获取 用户ID
	//value := l.ctx.Value("custom-key")

	file, err := l.svcCtx.BaiduSrv.DeleteFile(l.ctx, &baiduclient.DeleteFileRequest{
		Id: req.FileId,
	})

	if err != nil {
		return &types.Response{
			Msg:  err.Error(),
			Code: http.StatusAccepted,
			Data: nil,
		}, err
	}

	return &types.Response{
		Msg:  "File delete successful",
		Code: http.StatusOK,
		Data: file,
	}, nil
}
